Skip to content

Don't fail send_all retaining reserves for 0 channels #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tnull
Copy link
Collaborator

@tnull tnull commented May 16, 2025

Fixes #539.

Previouly, OnchainPayment::send_all_to_address would fail in the
retain_reserves mode if the maintained reserves were below the dust
limit. Most notably this would happen if we had no channels open at all.

Here, we fix this by simply falling back to the draining case (not
considering reserves) if the anchor reserves are below dust. We also add
a unit test that would have caught this regression in the first place.

Note: Github diff really messes up the first commit which is mostly adding an if and re-indenting the previous codeblock. It's best reviewed with git show --color-moved --ignore-all-space

Previouly, `OnchainPayment::send_all_to_address` would fail in the
`retain_reserves` mode if the maintained reserves were below the dust
limit. Most notably this would happen if we had no channels open at all.

Here, we fix this by simply falling back to the draining case (not
considering reserves) if the anchor reserves are below dust. We also add
a unit test that would have caught this regression in the first place.
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented May 16, 2025

👋 Thanks for assigning @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

tnull added 4 commits May 20, 2025 10:43
We create temporary transactions for fee estimation purposes. Doing this might
advance the descriptor state though. So here we call `cancel_tx` to tell
the wallet we no longer intend to broadcast the temporary transactions.
@tnull tnull force-pushed the 2025-05-fix-sendall-retaining-reserve-for-dust branch from 0c027cf to 1e5f4a2 Compare May 20, 2025 08:52
@tnull tnull requested a review from jkczyz May 20, 2025 08:53
Copy link

@m1sterc001guy m1sterc001guy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have less context here but this does look like it will fix our issue :)

Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after squash and any comments to clarify the test expections.

@tnull
Copy link
Collaborator Author

tnull commented May 21, 2025

LGTM after squash and any comments to clarify the test expections.

Squashed with the following additional changes:

> git diff-tree -U2 1e5f4a27 dc2902af
diff --git a/tests/integration_tests_rust.rs b/tests/integration_tests_rust.rs
index 1d33a14c..fde56620 100644
--- a/tests/integration_tests_rust.rs
+++ b/tests/integration_tests_rust.rs
@@ -530,4 +530,5 @@ fn onchain_send_all_retains_reserve() {
        node_a.sync_wallets().unwrap();
        node_b.sync_wallets().unwrap();
+       // Check node a sent all and node b received it
        assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, 0);
        assert!(((premine_amount_sat * 2 - onchain_fee_buffer_sat)..=(premine_amount_sat * 2))
@@ -556,4 +557,5 @@ fn onchain_send_all_retains_reserve() {
        expect_channel_ready_event!(node_b, node_a.node_id());

+       // Check node a sent all and node b received it
        assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, 0);
        assert!(((premine_amount_sat - reserve_amount_sat - onchain_fee_buffer_sat)
@@ -570,4 +572,5 @@ fn onchain_send_all_retains_reserve() {
        node_b.sync_wallets().unwrap();

+       // Check node b sent all and node a received it
        assert_eq!(node_b.list_balances().total_onchain_balance_sats, reserve_amount_sat);
        assert_eq!(node_b.list_balances().spendable_onchain_balance_sats, 0);

@tnull tnull requested a review from jkczyz May 21, 2025 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

send_all_to_address with retain_reserves creates 0 amount output
4 participants